package com.nf.health.app.adapter;

import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.SectionIndexer;

import com.nf.health.app.R;
import com.nf.health.app.models.RegimenContent;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

public class NewsAdapter extends BaseAdapter implements SectionIndexer, OnScrollListener{
	List<RegimenContent> newsList;
	Activity activity;
	LayoutInflater inflater = null;
	public NewsAdapter(Activity activity, List<RegimenContent> newsList) {
		this.activity = activity;
		this.newsList = newsList;
		inflater = LayoutInflater.from(activity);
	}
	@Override
	public int getCount() {
		return newsList == null ? 0 : newsList.size();
	}

	@Override
	public Object getItem(int position) {
		if (newsList != null && newsList.size() != 0) {
			return newsList.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		RegimenContent item = newsList.get(position);
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_health_news_content, position);
		ImageView iv_img = holder.getView(R.id.iv_img);
//		ImageView iv_play_btn = holder.getView(R.id.iv_play_btn);
		ImageLoaderUtils.getinstance(activity).getImage(iv_img, item.getImg(), R.drawable.default_image);
		holder.setText(R.id.tv_regimen_title, item.getTitle());

		if(TextUtils.isEmpty(item.getDescription())){
			holder.setText(R.id.tv_regimen_content, item.getDescs());
		}else{
			holder.setText(R.id.tv_regimen_content, item.getDescription());
		}
		
//		if(TextUtils.isEmpty(item.getMediaPath())&& TextUtils.isEmpty(item.getMediaType())){
//			iv_play_btn.setVisibility(View.GONE);
//		}else{
//			iv_play_btn.setVisibility(View.VISIBLE);
//		}
		
		return holder.getConvertView();
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {

	}
	//滑动监听
	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
	}

	@Override
	public Object[] getSections() {
		return null;
	}
	@Override
	public int getPositionForSection(int section) {
		return 0;
	}
	@Override
	public int getSectionForPosition(int position) {
		return 0;
	}
}
